import {
  ADD_COUNTER,
  ADD_TO_CART
} from "./mutations-types"
export default {
  addCart(context, payload) {
   return new Promise((resolve ) => {
     let oldProduct = context.state.cartList.find(function (item) {
       return item.iid === payload.iid
     })
     // 判断oldProduct
     if (oldProduct) {  //数量加1
       context.commit(ADD_COUNTER , oldProduct)
       resolve('当前的商品数量加1')
     } else {   //添加新商品
       payload.count = 1;
       context.commit(ADD_TO_CART , payload);
       resolve('添加新商品成功')
     }
   })
  }
}
